home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
mpw yacc ƒ src
/
files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-19
|
3KB
|
161 lines
#include <stdio.h>
#include "defs.h"
#ifdef MACINTOSH
#include <files.h>
#endif
#include "files.h"
#include "new.h"
extern char dflag;
extern char vflag;
extern char *prefix;
extern char *mktemp();
char *action_file_name = ACTION_FILE;
char *defines_file_name;
char *input_file_name;
char *parser_file_name = PARSER_FILE;
char *output_file_name;
char *temp_file_name = TEMP_FILE;
char *verbose_file_name;
FILE *action_file;
FILE *defines_file;
FILE *input_file;
FILE *parser_file;
FILE *output_file;
FILE *temp_file;
FILE *verbose_file;
openfiles()
{
int i;
#ifdef MACINTOSH
char name[256];
short refnum;
GetVol(name,&refnum);
#endif
i = strlen(prefix);
defines_file_name = NEW2(i + sizeof(DEFINES_FILE) + 1, char);
strcpy(defines_file_name, prefix);
strcpy(defines_file_name + i, DEFINES_FILE);
output_file_name = NEW2(i + sizeof(OUTPUT_FILE) + 1, char);
strcpy(output_file_name, prefix);
strcpy(output_file_name + i, OUTPUT_FILE);
verbose_file_name = NEW2(i + sizeof(VERBOSE_FILE) + 1, char);
strcpy(verbose_file_name, prefix);
strcpy(verbose_file_name + i, VERBOSE_FILE);
#ifndef MPWC
mktemp(action_file_name);
mktemp(temp_file_name);
#endif
if (!input_file)
{
input_file = fopen(input_file_name, "r");
if (input_file == NULL) open_error(input_file_name);
}
parser_file = fopen(parser_file_name, "r");
if (parser_file == NULL) open_error(parser_file_name);
#ifdef MACINTOSH
strcpy(name,action_file_name);
c2pstr(name);
FSDelete(name,refnum);
Create(name,refnum,'MPS ','TEXT');
#endif
action_file = fopen(action_file_name, "w");
if (action_file == NULL) open_error(action_file_name);
if (vflag)
{
#ifdef MACINTOSH
strcpy(name,verbose_file_name);
c2pstr(name);
FSDelete(name,refnum);
Create(name,refnum,'MPS ','TEXT');
#endif
verbose_file = fopen(verbose_file_name, "w");
if (verbose_file == NULL) open_error(verbose_file_name);
}
if (dflag)
{
defines_file = fopen(defines_file_name, "r");
if (defines_file == NULL)
{
#ifdef MACINTOSH
strcpy(name,defines_file_name);
c2pstr(name);
FSDelete(name,refnum);
Create(name,refnum,'MPS ','TEXT');
#endif
defines_file = fopen(defines_file_name, "w");
if (defines_file == NULL) open_error(defines_file_name);
temp_file = defines_file;
}
else
{
#ifdef MACINTOSH
strcpy(name,temp_file_name);
c2pstr(name);
FSDelete(name,refnum);
Create(name,refnum,'MPS ','TEXT');
#endif
temp_file = fopen(temp_file_name, "w");
if (temp_file == NULL) temp_file = defines_file;
}
}
#ifdef MACINTOSH
strcpy(name,output_file_name);
c2pstr(name);
FSDelete(name,refnum);
Create(name,refnum,'MPS ','TEXT');
#endif
output_file = fopen(output_file_name, "w");
if (output_file == NULL) open_error(output_file_name);
}
tidy()
{
if (action_file != NULL)
{
fclose(action_file);
ZAPFILE(action_file_name);
}
if (dflag)
{
if (defines_file != NULL)
{
if (defines_file == temp_file)
{
fclose(defines_file);
temp_file = NULL;
}
}
if (temp_file != NULL)
{
fclose(temp_file);
ZAPFILE(temp_file_name);
}
}
if (vflag && verbose_file != NULL) fclose(verbose_file);
if (input_file != NULL) fclose(input_file);
if (parser_file != NULL) fclose(parser_file);
if (output_file != NULL) fclose(output_file);
}